<?php

/**
 * Fusion Models main page
 * @package ModuleGestionDocuments
 * @version 1.0b
 */

session_start();

// Configuration file
include 'configuration.php';
// Functions
include 'inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	header('Location: index.php');
	exit();
endif;

// Include all objects
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

// ---------- START: HEAD
include $configuration['webroot'].'inc/head.php';
// ---------- END: HEAD

// ---------- START: MENU
include $configuration['webroot'].'inc/menu.php';
// ---------- END: MENU

// ---------- START: BODY

$model = new Model();
$modelList = $model->GetList(); ?>

<table cellpadding="0" cellspacing="0" border="0" class="table-objects">
	<tr>
		<th class="del"></th>
		<th>Fichier</th>
		<th>Auteur</th>
		<th>Ajouté le</th>
	</tr>
	<?php foreach ($modelList as $model) {
		$crmuser = $model->GetCrmuser();
		$crmcontact = $crmuser->GetContact();
		$date = explode('-', $model->date);
		$date = $date[2].'/'.$date[1].'/'.$date[0];
		
		$res  = '<tr>';
		$res .= '<td class="del"><a href="'.$model->modelId.'" class="delete-doc"><img src="css/img/bin_empty.png" alt="Delete" /></a></td>';
		$res .= '<td><a href="'.$configuration['appdir'].'data/models/'.$model->modelId.'.'.$model->extension.'" target="_blank" class="file">'.$model->filename.'.'.$model->extension.'</a></td>';
		$res .= '<td><a href="crmusers.php?id='.$crmuser->crmuserId.'&operation=edit"><strong>'.$crmcontact->lastname.' '.$crmcontact->firstname.'</strong></a></td>';
		$res .= '<td>'.$date.'</td>';
		$res .= '</tr>';
		echo $res;
	} ?>
</table>
<form action="" method ="post" class="form-crud">
<table cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td class="form-crud-label"><label for="model-file-upload">Ajouter des modèles :</label></td>
		<td class="form-crud-input"><input id="model-file-upload" name="model-file-upload" type="file" /></td>
		<td class="form-crud-label"></td>
		<td class="form-crud-input"></td>
	</tr>
	<tr>
		<td class="form-crud-label"></td>
		<td class="form-crud-input"><a href="javascript:$('#model-file-upload').uploadifyUpload()" class="upload">Upload</a></td>
		<td class="form-crud-label"></td>
		<td class="form-crud-input"></td>
	</tr>
</table>
</form>

<?php
// ---------- END: BODY

// ---------- START: FOOT
include $configuration['webroot'].'inc/foot.php';
// ---------- END: FOOT

// ---------- JAVASCRIPTS AND END
include $configuration['webroot'].'inc/js.php'; ?>
<script type="text/javascript" src="js/models.js"></script>

</body>
</html>